package com.qfedu.controller;

import com.github.pagehelper.Page;
import com.qfedu.common.JsonResult;
import com.qfedu.pojo.Notice;
import com.qfedu.pojo.User;
import com.qfedu.service.NoticeService;
import com.qfedu.util.StrUtils;
import com.qfedu.vo.VONotice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/notice")
public class NoticeController {
    @Autowired
    private NoticeService noticeService;

    @RequestMapping("/all.do")
    @ResponseBody
    public Map<String, Object> findAll(HttpSession session, Integer page, Integer limit) {
//        User user = (User) session.getAttribute(StrUtils.LOGIN_USER);
        List<VONotice> all = noticeService.findAll(page, limit);
        Map<String, Object> map = new HashMap<>();

        long total = ((Page) all).getTotal();

        map.put("code", 0);
        map.put("msg", "");
        map.put("count", total);
        map.put("data", all);

        return map;
    }
    @RequestMapping("/add.do")
    @ResponseBody
    public JsonResult addNotice(HttpSession session,Notice notice) {
//        User user = (User) session.getAttribute(StrUtils.LOGIN_USER);
        noticeService.addNotice(notice);
        return new JsonResult(0, "添加成功");
    }
    @RequestMapping("/delete.do")
    @ResponseBody
    public JsonResult deleteNotice(int id) {
        noticeService.deleteNotice(id);
        return new JsonResult(0, "删除成功");
    }
}